# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
from suds.client import Client
import json


class HeimaoPipeline:
    # 保存本地
    # def process_item(self, item, spider):
    #     file_path = r'./data.txt'
    #     with open(file_path, 'a', encoding='gb18030') as f:
    #         print('正在写入：{}'.format(item))
    #         f.write(str(item) + '\n')
    #     return item

    def process_item(self, item, spider):
        if spider.name == 'xinlang':
            dict_item = dict(item)
            self.uploading(dict_item)
        return item

    def uploading(self, data):
        proxy_host = 'http://agent.xunku.org:8888/axis2/services/AgentService?wsdl'
        proxy = Client(proxy_host)
        status = proxy.service.uploadAppNews(json.dumps(data,
                                                        ensure_ascii=False))

